package com.anntly.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @Auther: 张文
 * @Date: 2020/5/10 19:25
 * @Description:
 */
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {

    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 向管道加入处理器
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 使用netty提供的httpServerCodec 处理http
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());
        // 自定义处理器
        pipeline.addLast("MyTestHttpServerHandler",new TestHttpServerHandler());
    }
}
